package com.tree.rpc.socket.consumer;

import com.tree.rpc.socket.remote.pojo.RpcTransformObj;
import com.tree.rpc.socket.remote.pojo.ServiceMapped;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @ClassName com.tree.rpc.socket.consumer
 * Description: <类功能描述>. <br>
 * <p>
 * <使用说明>
 * </p>
 * @Author tree
 * @Date 2019-11-07 00:38
 * @Version 1.0
 */
public class RpcInvocationHandler implements InvocationHandler {
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        RpcTransformObj obj = new RpcTransformObj();
        Class<?> clazz = method.getDeclaringClass();

        //通过在service 的注解获取实现类的全路径
        String fullClassName = clazz.getDeclaredAnnotation(ServiceMapped.class).mappedService();
        obj.setFullName(fullClassName);
        obj.setMethodName(method.getName());
        obj.setParams(args);


        return new BioSocketClient().callRemoteServer(obj,"localhost",8080);
    }
}
